/*!
 Temelia - Splay tree interface.

 Copyright (C) 2008, 2009 Ceata (http://cod.ceata.org/proiecte/temelia).

 @author Dascalu Laurentiu

 This program is free software; you can redistribute it and
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 3
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef SPLAY_H_
#define SPLAY_H_

#include "platform.h"
#include "binary_tree_common.h"

struct _splay_tree_node;
typedef struct _splay_tree_node *splay_tree_node;

/*!
 * @see binary_tree_new
 */
DECLSPEC splay_tree_t splay_tree_new(void *key);

/*!
 * @see binary_tree_delete_node
 */
DECLSPEC void splay_tree_delete_node(splay_tree_t splay);

/*!
 * @see binary_tree_delete
 */
DECLSPEC void splay_tree_delete(splay_tree_t splay);

/*!
 * @see binary_tree_compare_trees
 */
DECLSPEC int splay_tree_compare_trees(splay_tree_t splay1, splay_tree_t splay2,
		int compare(void *x, void *y, void *context), void *context);

/*!
 * @see binary_tree_is_empty
 */
DECLSPEC int splay_tree_is_empty(splay_tree_t splay);

/*!
 * @see binary_tree_is_leaf
 */
DECLSPEC int splay_tree_is_leaf(splay_tree_t splay);

/*!
 * @see binary_tree_get_size
 * Complexity O(1)
 */
DECLSPEC int splay_tree_get_size(splay_tree_t splay);

/*!
 * @see binary_tree_get_root
 */
DECLSPEC splay_tree_t splay_tree_get_root(splay_tree_t splay);

/*!
 * @see binary_tree_get_key
 */
DECLSPEC void *splay_tree_get_key(splay_tree_t splay);

/*!
 * @see binary_tree_get_parent
 */
DECLSPEC splay_tree_t splay_tree_get_parent(splay_tree_t splay);

/*!
 * @see binary_tree_get_left_child
 */
DECLSPEC splay_tree_t splay_tree_get_left_child(splay_tree_t splay);

/*!
 * @see binary_tree_get_right_child
 */
DECLSPEC splay_tree_t splay_tree_get_right_child(splay_tree_t splay);

/*!
 * @see binary_tree_get_height
 */
DECLSPEC int splay_tree_get_height(splay_tree_t splay);

/*!
 * @see binary_tree_get_depth
 */
DECLSPEC int splay_tree_get_depth(splay_tree_t splay);

/*!
 * @see binary_search_tree_search
 */
DECLSPEC splay_tree_t splay_tree_search(splay_tree_t splay, void *key, int compare(
		void *x, void *y, void *context), void *context);

/*!
 * @see binary_search_tree_insert
 * @return New splay tree's root
 */
DECLSPEC splay_tree_t splay_tree_insert(splay_tree_t splay, void *key, int compare(
		void *x, void *y, void *context), void *context);

/*!
 * @see binary_search_tree_remove
 * @return The new splay tree's root
 */
DECLSPEC splay_tree_t splay_tree_remove(splay_tree_t _splay_tree, void *key,
		int compare(void *x, void *y, void *context), void *context);

/*!
 * @see binary_search_tree_get_min
 */
DECLSPEC splay_tree_t splay_tree_get_min(splay_tree_t splay);

/*!
 * @see binary_search_tree_get_max
 */
DECLSPEC splay_tree_t splay_tree_get_max(splay_tree_t splay);

/*!
 * @see binary_tree_preorder
 */
DECLSPEC void splay_tree_preorder(splay_tree_t splay, void key_handler(void *x,
		void *context), void *context);
/*!
 * @see binary_tree_inorder
 */
DECLSPEC void splay_tree_inorder(splay_tree_t splay, void key_handler(void *x,
		void *context), void *context);

/*!
 * @see binary_tree_reverse_inorder
 */
DECLSPEC void splay_tree_reverse_inorder(splay_tree_t splay, void key_handler(void *x,
		void *context), void *context);

/*!
 * @see binary_tree_postorder
 */
DECLSPEC void splay_tree_postorder(splay_tree_t splay, void key_handler(void *x,
		void *context), void *context);

/*!
 * @see binary_tree_level_order
 */
DECLSPEC void splay_tree_level_order(splay_tree_t splay, void key_handler(void *x,
		void *context), void *context);

/*!
 * @see binary_tree_show_indented
 */
DECLSPEC void splay_tree_show_indented(splay_tree_t splay, void key_handler(void *x,
		int level, void *context), void *context);

#endif /* SPLAY_H_ */
